import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { defHttp } from '/@/utils/http/axios';
import { UploadTypeEnum } from '/@/components/Form/src/jeecg/components/JUpload';
//列表数据
export const columns : BasicColumn[] = [
	{
		title: '审核状态',
		align: "center",
		dataIndex: 'stats',
		customRender: ({ text }) => {
			if (text == 'Fail') return '审核未通过'
			if (text == 'Verified') return '审核通过'
			if (text == 'Audit') return '审核中'
		}
	},
	{
		title: '攻略/游记',
		align: "center",
		dataIndex: 'typeId',
		customRender: ({ text }) => {
			if (text == 'Travel') return '游记'
			if (text == 'Strategy') return '攻略'
		}
	},
	{
		title: '标签',
		align: "center",
		dataIndex: 'tags',
		customRender: ({ text }) => {
			let tags = JSON.parse(text)
			return tags.join(',')
		}
	},
	{
		title: '标题',
		align: "center",
		dataIndex: 'title'
	},
	{
		title: '标题',
		align: "center",
		dataIndex: 'title'
	},
	{
		title: '排序',
		align: "center",
		sorter: true,
		dataIndex: 'sort'
	},
	{
		title: '点赞数',
		align: "center",
		sorter: true,
		dataIndex: 'zanNum'
	},
	{
		title: '发布人',
		align: "center",
		dataIndex: 'userId_dictText'
	},
	{
		title: '评论数量',
		align: "center",
		sorter: true,
		dataIndex: 'commentNum'
	},

	{
		title: '图片',
		align: "center",
		dataIndex: 'img',
		customRender: ({ text }) => {
			let imgs = JSON.parse(text)
		/* 	let is=''
			for(let i=0;i<imgs.length;i++){
				is+=imgs[i].url+","
			}
			is = is.substring(0, is.length -1);  // 使用substring方法从字符串中去除最后两个字符（即逗号和空格）
			return render.renderImage({ text: is }) */
			return render.renderImage({ text: imgs.join(',') })
			//return render.renderImage({ text: imgs.url.join(',') })
		}
	},
	{
		title: '视频',
		align: "center",
		dataIndex: 'video'
	},
	{
		title: '分享次数',
		align: "center",
		sorter: true,
		dataIndex: 'shareNum'
	},
	{
		title: '浏览量',
		align: "center",
		sorter: true,
		dataIndex: 'browseNum'
	},
	/* {
		title: '租户',
		align: "center",
		dataIndex: 'tenantId_dictText'
	}, */
	{
		title: '发布地址',
		align: "center",
		sorter: true,
		dataIndex: 'extinfors',
		customRender: ({ text }) => {
			let o = JSON.parse(text)
			return o.addressInfo.district + o.addressInfo.name
		}

	},
	{
		title: '人均',
		align: "center",
		sorter: true,
		dataIndex: 'extinfors',
		customRender: ({ text }) => {
			let o = JSON.parse(text)
			return "￥" + o.cost
		}

	},


];
//查询数据
export const searchFormSchema : FormSchema[] = [
	{
		label: "类别",
		field: 'typeId',
		component: 'JDictSelectTag',
		componentProps: {
			options: [
				{ label: '游记', value: 'Travel' },
				{ label: '攻略', value: 'Strategy' },
			]
		},
		//colProps: {span: 6},
	},
	{
		label: "发布人",
		field: 'userId',
		component: 'JSearchSelect',
		componentProps: {
			dict: "BS_UserLayout_UserInfor,nickName,id"
		},
		//colProps: {span: 6},
	},
	{
		label: "内容",
		field: 'content',
		component: 'Input',
		//colProps: {span: 6},
	},
	{
		label: "租户",
		field: 'tenantId',
		component: 'JDictSelectTag',
		componentProps: {
			dictCode: "sys_tenant,name,id"
		},
		//colProps: {span: 6},
	},
];
//表单数据
export const formSchema : FormSchema[] = [
	{
		label: '发布时间',
		field: 'createTime',
		component: 'DatePicker',
		componentProps: {
			showTime: true,
			valueFormat: 'YYYY-MM-DD HH:mm:ss'
		},
	},
	{
		label: "审核状态",
		field: 'stats',
		component: 'JDictSelectTag',
		componentProps: {
			options: [
				{ label: '审核通过', value: 'Verified' },
				{ label: '审核未通过', value: 'Fail' },
				{ label: '待审核', value: 'Audit' },
			]
		},
		//colProps: {span: 6},
		show: ({ values }) => {
			return values.isUpdate == true
		},
	},
	{
		label: "攻略/游记",
		field: 'typeId',
		component: 'JDictSelectTag',
		componentProps: {
			options: [
				{ label: '游记', value: 'Travel' },
				{ label: '攻略', value: 'Strategy' },
			]
		},
		//colProps: {span: 6},
	},

	/* 	{
			label: '标签',
			field: 'tagIds',
			component: 'ApiSelect',
			required: true,
			componentProps: ({ formActionType, formModel }) => {
				return {
					//multiple: 多选；不填写为单选
					mode: 'multiple',
					//请求api,返回结果{ result: { records: [{'id':'1',name:'scott'},{'id':'2',name:'小张'}] }}
					api: () => defHttp.get({ url: '/activity/bsActiveItem/getStrategyTypesByRedisSelect' }),
					//数值转成String
					numberToString: false,
					//标题字段
					labelField: 'gtitle',
					//值字段
					valueField: 'id',
					//请求参数
					params: {
						carpoolBus: formModel.carpoolBus
					},
					//返回结果字段
					resultField: 'records'
				}
	
			},
		}, */
	{
		label: '标题',
		field: 'title',
		component: 'Input',
	},

	{
		label: '发布人',
		field: 'userId',
		component: 'JSearchSelect',
		componentProps: {
			dict: "BS_UserLayout_UserInfor,nickName,id"
		},
	},
	/* 	{
			label: '评论数量',
			field: 'commentNum',
			component: 'Input',
		}, */
	{
		label: '内容',
		field: 'content',
		component: 'InputTextArea',
	},
	{
		label: '图片',
		field: 'imgs',
		component: 'JUpload',
		helpMessage: '最多上传9张图片',
		componentProps: {
			fileType: UploadTypeEnum.image,
			maxCount: 9,
		},
	},
	{
		label: '视频',
		field: 'video',
		component: 'JUpload',
		componentProps: { maxCount: 1 },
	},
	{
		label: '点赞量',
		field: 'zanNum',
		component: 'InputNumber',
	},
	{
		label: '排序',
		field: 'sort',
		component: 'InputNumber',
	},
	/* 	{
			label: '标签',
			field: 'tags',
			component: 'Input',
		}, */

	// TODO 主键隐藏字段，目前写死为ID
	{
		label: '',
		field: 'id',
		component: 'Input',
		show: false
	},
	{
		label: '',
		field: 'isUpdate',
		component: 'Input',
		show: false
	},
	{
		label: '',
		field: 'img',
		component: 'Input',
		show: false
	},
];



/**
* 流程表单调用这个方法获取formSchema
* @param param
*/
export function getBpmFormSchema(_formData) : FormSchema[] {
	// 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
	return formSchema;
}